<template>
    <div class="ct-bodySet">
        <el-container>
            <el-header class="bgclr-dk-sp0 mb20 headerCoster">
                <el-breadcrumb separator-class="el-icon-arrow-right">
                    <el-breadcrumb-item :to="{ path: '/mainPage/welcome' }"
                        >首页</el-breadcrumb-item
                    >
                    <el-breadcrumb-item>下载统计</el-breadcrumb-item>
                    <el-breadcrumb-item
                        ><span class="main-Clr-ft"
                            >信息查询</span
                        ></el-breadcrumb-item
                    >
                </el-breadcrumb>
            </el-header>
            <div class="pl20 pr20">
                <el-card class="mb20 cardWidth">
                    <el-form
                        :inline="true"
                        :model="formData"
                        ref="formData"
                        class="noMarginBottom"
                    >
                        <el-form-item class="mb1" label="所属区域：">
                            <el-select
                                v-model="formData.groupname"
                                placeholder="请选择"
                                clearable 
                            >
                                <el-option
                                    v-for="item in groupname"
                                    :label="item.value"
                                    :value="item"
                                    :key="item.id"
                                >
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item class="mb1" label="姓名：">
                            <el-input
                                placeholder="请输入内容"
                                v-model="formData.input10"
                                clearable
                            >
                            </el-input>
                        </el-form-item>
                        <el-button type="primary" @click="queryList()"
                            >查询</el-button
                        >
                    </el-form>
                </el-card>
                <el-card class="mb20 cardWidth">
                    <template>
                         <!--导出 -->
                         <template>
                              <!--搜索 -->                            
                            <el-popover
                                placement="bottom"
                                trigger="click"
                            >
                                <el-input v-model="search"  placeholder="输入关键字搜索"/>
                                <el-button
                                        class="el-icon-search"
                                        type="text"
                                        size="medium"
                                        slot="reference"
                                >
                                    <span>搜索</span>
                                </el-button>
                            </el-popover>
                            <span>
                                <img style="padding-top:9px;padding-left:10px" src="static/icon/导出.png"/>
                                <el-button 
                                    type="text"  
                                    size="medium" 
                                    slot="reference"
                                    @click="htmlToExcel('#printTest', '表格')">
                                    导出Excel
                                </el-button>
                            </span>
                        </template>    
                        <el-table
                            ref="tableCot"
                            border
                            stripe
                            :header-cell-style="getRowClass"
                            :data="securityList.filter(data => !search || data.username.toLowerCase().includes(search.toLowerCase()))"
                            style="width: 100%"
                            :max-height="height"
                            id="printTest"
                            :default-sort ="{prop:'date',order:'descending'}"
                        >   
                            <el-table-column 
                                prop="groupname" label="所属区域"
                                sortable>
                            </el-table-column>
                            <el-table-column 
                                prop="username" label="姓名"
                                sortable>
                            </el-table-column>
                            <el-table-column 
                                prop="asset_library" label="资产库"
                                sortable>
                            </el-table-column>
                             <el-table-column 
                                prop="download_date" label="下载日期"
                                sortable>
                            </el-table-column>
                            <el-table-column 
                                prop="file_name" 
                                label="下载成果物文件"
                                width="450"
                                sortable>
                            </el-table-column>
                            <el-table-column
                                prop="download_number"
                                label="下载次数"
                                sortable
                            >
                            </el-table-column>
                             <!--自定义无数据显示 -->
                            <div slot="empty">
                                <p>
                                    <img src="static/icon/无搜索结果.png"/>
                                </p>
                                <p style="padding-top:40px"><span>暂无数据</span></p>
                            </div>
                        </el-table>
                    </template>
                    <el-col :span="24">
                        <div><br /></div>
                    </el-col>
                </el-card>
            </div>
            <div class="bottomLayoutBus"></div>
        </el-container>
    </div>
</template>

<script>
import urlConfig from "../../../config/url.json";
import Vue from "vue";
import { Message } from "element-ui";
import FileSaver from "file-saver";
import XLSX from "xlsx";
Vue.component(Message.name, Message);
let queryFileDownloadNumberUrl = urlConfig.queryFileDownloadNumber;
export default {
    name: "",
    data() {
        return {
            formData: {
                input10: '',
                groupname:''
            },
            input10: "",
            groupname:[{code:1,value:"解决方案组"},
                       {code:2,value:"交付中心（北部）"},
                        {code:3,value:"交付中心（东部）"},
                         {code:4,value:"交付中心（西部）"},
                          {code:5,value:"交付中心（南部）"}],
            securityList: [],
            search:'',
            height: window.innerHeight - 330,
        };
    },
    methods: {
        queryList() {
            //查询
            debugger;
            let that = this;
            const loading = this.$loading({
                lock: true,
                text: "Loading",
                spinner: "el-icon-loading",
            });
            that.$http({
                method: "post",
                url: queryFileDownloadNumberUrl,
                baseURL: "/api",
                data: {
                    username: that.formData.input10,
                    groupname: that.formData.groupname.value
                },
            })
                .then(function (response) {
                    if (response.data.code == 1) {
                        that.securityList = response.data.data;
                        Message.success("查询成功");
                    } else {
                        Message.error("查询失败");
                    }
                    loading.close();
                })
                .catch(function (err) {
                    console.log(err);
                    Message.error("查询失败");
                    loading.close();
                });
        },
        //表头颜色
        getRowClass({ rowIndex }) {
            if (rowIndex == 0 || rowIndex == 1) {
                return "background:#2FB2B8;color: white";
            } else {
                return "";
            }
        },
        //Table高度
        getHeight() {
            let that = this;
            that.height = window.innerHeight - 159;
        },
        //导出Excel
        htmlToExcel(dom, title = "成果物下载次数统计") {
            debugger;
            const wb = XLSX.utils.table_to_book(document.querySelector(dom));
            const wbout = XLSX.write(wb, {
                bookType: "xlsx",
                bookSST: true,
                type: "array",
            });
            const blob = new Blob([wbout], {
                type: "application/octet-stream",
            });
            FileSaver.saveAs(blob, `成果物下载次数统计.xlsx`);
        },
    },
    mounted() {
        this.queryList();
    },
    //自适应高度
    created() {
        let that = this;
        window.addEventListener("resize", that.getHeight);
    },
    destroyed() {
        let that = this;
        window.removeEventListener("resize", that.getHeight);
    },
};
</script>

<style scoped>
.headerCoster {
    height: 59px;
    border-top: 1px solid #eee;
    border-bottom: 1px solid #eee;
}

.deleteButtonColor {
    color: red;
}

.submitButtonColor {
    color: green;
}

.letBorder {
    border-left: #6aabe6 solid 1px;
}

.def-el-input {
    -webkit-appearance: none;
    background-color: #fff;
    background-image: none;
    border-radius: 4px;
    border: 1px solid #dcdfe6;
    box-sizing: border-box;
    color: #606266;
    display: inline-block;
    font-size: inherit;
    height: 40px;
    line-height: 40px;
    outline: none;
    padding: 0 15px;
    width: 35%;
}

.cardWidth {
    width: 100%;
}
.el-select {
    width: 100%;
}
.el-table {
    overflow: auto;
}
.el-table ::-webkit-scrollbar{
  width:10px;
  height:10px;
  /**/
}
.el-table ::-webkit-scrollbar-track{
  background: rgb(239, 239, 239);
  border-radius:2px;
}
.el-table ::-webkit-scrollbar-thumb{
  background: #bfbfbf;
  border-radius:10px;
}
</style>